import { createApp } from "vue";
import { createPinia } from "pinia";
import "reflect-metadata";
import "../src/assets/styles/var.css";
import "@chulei-ui/components/lib/style.css";
import "@chulei-ui/element-plus/dist/index.css";
import "@chulei-ui/element-plus/theme-chalk/dark/css-vars.css";
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
import ChuleiUI from "@chulei-ui/components";
import dayjs from "dayjs";
import duration from "dayjs/plugin/duration";
import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";
import "dayjs/locale/zh-cn";
import relativeTime from "dayjs/plugin/relativeTime";
import { ElNotification } from "@chulei-ui/element-plus";
import router, { plugin } from "../routers";
import App from "./App.vue";
import { initDatabase } from "./repositories";
dayjs.extend(utc);

dayjs.extend(timezone);
dayjs.locale("zh-cn");
dayjs.extend(duration);
dayjs.extend(relativeTime);
const pinia = createPinia();
pinia.use(piniaPluginPersistedstate);
const app = createApp(App);
app.use(ChuleiUI);
app.use(pinia);
app.use(router);
app.use(plugin);
app.config.errorHandler = (err: any) => {
  if (err.name === "ESIError") {
    ElNotification({
      type: "error",
      title: "ESI接口调用出错",
      message: err.code,
    });
  }
  console.error(err);
};
initDatabase().then(() => {
  app.mount("#app");
});
